# -*- coding: utf-8 -*-
# coding=utf-8
'''
Created on 2014-3-20

@author: SimonFu
'''
import os
import sys
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parentdir)

import codecs
import csv
import DBCenter



'''
    导入category
'''

def RunCheck():
    csvfile = open('category.csv', 'r')
    reader = csv.reader(csvfile)
    print(reader)
    for row in reader:
        insert_sql = '''
            INSERT INTO `category`
                        (`category_id`,
                         `category_name`,
                         `category_level`,
                         `parent_id`,
                         `parent_name`,
                         `category_id1`,
                         `category_name1`,
                         `category_id2`,
                         `category_name2`,
                         `category_id3`,
                         `category_name3`,
                         `seo_title`,
                         `seo_keyword`,
                         `seo_description`,
                         `sort`,
                         `status`)
                VALUES ('%s',
                        '%s',
                        %s,
                        '%s',
                        '%s',
                        '%s',
                        '%s',
                        '',
                        '',
                        '',
                        '',
                        NULL,
                        NULL,
                        NULL,
                        0,
                        1);
        ''' % (row[0], 
               row[1].decode('gbk').encode('utf8'), 
               row[2], 
               row[3],
               row[4].decode('gbk').encode('utf8'), 
               row[5],
               row[6].decode('gbk').encode('utf8'), 
               )
        try:
            DBCenter.rc_db.execute(insert_sql)
        except:
            print insert_sql
            
def Run():
    RunCheck()
    
Run()
# print os.getcwd()
